package com.angus.api.front.factory;

import com.angus.api.front.RemoteFrontLogService;
import com.angus.api.front.domain.FrontLoginInfo;
import com.angus.api.front.domain.FrontOperLog;
import com.angus.common.core.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 日志服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteFrontLogFallbackFactory implements FallbackFactory<RemoteFrontLogService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteFrontLogFallbackFactory.class);

    @Override
    public RemoteFrontLogService create(Throwable throwable)
    {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new RemoteFrontLogService()
        {
            @Override
            public R<Boolean> saveLog(FrontOperLog frontOperLog, String source)
            {
                return R.fail("保存操作日志失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> saveLoginInfo(FrontLoginInfo frontLoginInfo, String source)
            {
                return R.fail("保存登录日志失败:" + throwable.getMessage());
            }
        };

    }
}
